package com.brsya.movie.presenter;

import com.brsya.base.base.BasePresenter;
import com.brsya.base.bean.BaseListBean;
import com.brsya.base.bean.InventoryBean;
import com.brsya.base.net.MyObserver;
import com.brsya.base.net.RxScheduler;
import com.brsya.movie.contract.InventoryContract;
import com.brsya.movie.model.InventoryModel;

import java.util.Map;

import io.reactivex.rxjava3.annotations.NonNull;

/**
 * Created by Brsya
 * CreateDate: 2022/7/7  9:34
 * Description:
 * 片单逻辑层
 */
public class InventoryPresenter extends BasePresenter<InventoryContract.View> implements InventoryContract.Presenter {
    private InventoryContract.Model model;

    public InventoryPresenter() {
        model = new InventoryModel();
    }

    @Override
    public void getInventoryList(int id) {
        mView.showLoading();

        Map<String, Object> par = getPublicPar();
        if (id > 0) {
            par.put("hvId", id);
        }

        model.getInventory(par)
                .compose(RxScheduler.Obs_io_main())
                .to(mView.bindAutoDispose())
                .subscribe(new MyObserver<BaseListBean<InventoryBean>>(mView) {
                    @Override
                    public void success(@NonNull BaseListBean<InventoryBean> baseBean) {
                        baseBean.handleData(InventoryBean.class);
                        if (baseBean.getData() == null || baseBean.getData().size() == 0) {
                            mView.inventoryNoData();
                            return;
                        }
                        mView.showInventoryList(baseBean.getData());
                    }
                });
    }
}
